import ast
from django.db import models
from django.contrib.auth.models import AbstractUser

class UserProfile(AbstractUser):
    '''
    用户信息
    '''
    name = models.CharField(max_length=30,verbose_name="姓名")
    birthday = models.DateField(null=True,blank=True,verbose_name="出生日期")
    gender = models.CharField(max_length=6,choices=(("male","男"),("female","女")),default="female",verbose_name="性别")
    mobile = models.CharField(max_length=11,null=True,blank=True,verbose_name="手机")
    email = models.EmailField(null=True,blank=True,verbose_name="邮箱")
    avator = models.URLField(null=True,blank=True,default="https://ops-prod.oss-cn-hangzhou.aliyuncs.com/user.png")
    department = models.CharField(max_length=40,null=True,blank=True,verbose_name="部门",help_text="部门")
    role = models.CharField(max_length=20,choices=(("adminstrator","管理员"),("general","使用者")),default="general",verbose_name="角色",help_text="角色")
    auth_group = models.CharField(max_length=100,default="default",verbose_name="权限组",help_text="权限组")



    class Meta:
        verbose_name = "用户"
        verbose_name_plural = verbose_name
        db_table = "user_profile"

    def __str__(self):
        return self.username

class Grained(models.Model):
    auth_group = models.CharField(max_length=50,db_index=True,unique=True,error_messages={'unique':'名称只能唯一'},verbose_name="权限组名称",help_text="权限组名称")
    permissions = models.TextField(verbose_name="权限",help_text="权限")
    create_time = models.DateTimeField(auto_now_add=True,verbose_name="创建时间",help_text="创建时间")
    update_time = models.DateTimeField(auto_now=True,verbose_name="更新时间",help_text="更新时间")


    class Meta:
        verbose_name = "权限组"
        verbose_name_plural = verbose_name
        ordering = ['id']
        db_table = "grained"